#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: 蒋艰坚
@file: MY_OCR.py
@time: 2021/7/7 8:31
@desc: 
"""

import cv2
import paddlehub as hub


def My_OCR(file_path):
    # 加载移动端预训练模型
    ocr = hub.Module(name="chinese_ocr_db_crnn_mobile")

    # 读取测试文件夹test.txt中的照片路径
    np_images = [cv2.imread(file_path)]

    results = ocr.recognize_text(
        images=np_images,  # 图片数据，ndarray.shape 为 [H, W, C]，BGR格式；
        use_gpu=False,  # 是否使用 GPU；若使用GPU，请先设置CUDA_VISIBLE_DEVICES环境变量
        visualization=False,  # 是否将识别结果保存为图片文件；
        box_thresh=0.8,  # 检测文本框置信度的阈值；
        text_thresh=0.8)  # 识别中文文本置信度的阈值；

    data = results[0]['data']
    return data

    # for infomation in data:
    #     print('text: ', infomation['text'], '\nconfidence: ', infomation['confidence'], '\ntext_box_position: ',
    #           infomation['text_box_position'])
